﻿using Microsoft.Office.Interop.Excel;
using Microsoft.Office.Core;
using System;

namespace VSTODemo
{
    public partial class ThisAddIn
    {
        public static Application ExcelApp;

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            ExcelApp = Globals.ThisAddIn.Application;

            // 初始化TaskPane
            ClipBoardPro clipboard = new ClipBoardPro();
            TaskPaneShared.taskPane = Globals.ThisAddIn.CustomTaskPanes.Add(clipboard, "剪贴板");
            TaskPaneShared.taskPane.DockPosition = MsoCTPDockPosition.msoCTPDockPositionRight;
            TaskPaneShared.taskPane.DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;
            TaskPaneShared.taskPane.Width = 500;

            // VisibleChange Event
            TaskPaneShared.taskPane.VisibleChanged += new System.EventHandler(taskpane_VisibleChanged);
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        private void taskpane_VisibleChanged(object sender, EventArgs e)
        {
            Ribbon1 ribbon1 = Globals.Ribbons.GetRibbon<Ribbon1>();
            ribbon1.cbShowTaskPanel.Checked = TaskPaneShared.taskPane.Visible;
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
}
